/**
 * Created by JetBrains WebStorm.
 * User: dimas
 * Date: 16.09.11
 * Time: 23:05
 */

function StatisticsClass() {
    var keys = {prefix:"size_"}
    this.getKeys = function(){return keys;}
    var best = [];
    var allScores = [];
    var startedGames = [];
    var completedGames = [];
    this.getBest = function(){return best;}
    this.getAllScores = function(){return allScores;}
    this.getStartedGames = function(){return startedGames;}
    this.getCompletedGames = function(){return completedGames;}
}

/**
 * Scores
 * @param mapSize
 */
StatisticsClass.prototype.getBestScore = function(mapSize){
    var key = this.getKeys().prefix + mapSize;
    return this.getBest()[key] || 0;
}
StatisticsClass.prototype.setScore = function(score, mapSize){
    var key = this.getKeys().prefix + mapSize;

    /**
     * save score
     */
    var allScores = this.getAllScores();
    if(!allScores[key]){
        allScores[key] = [];
    }
    allScores[key].push(score);

    var best = this.getBest();
    if(best[key] && typeof best[key] == 'number'){
        best[key] < score ? (best[key] = score) : null;
    }else{
        best[key] = score;
    }
}

/**
 * started games
 * @param mapSize
 */
StatisticsClass.prototype.getStartedGamesCount = function(mapSize){
    var key = this.getKeys().prefix + mapSize;
    return this.getStartedGames()[key] || 0;
}
StatisticsClass.prototype.addStartedGames = function(mapSize){
    var key = this.getKeys().prefix + mapSize;
    var arr = this.getStartedGames();
    arr[key] ? arr[key]++ : arr[key] = 1;
}
StatisticsClass.prototype.getCompletedGamesCount = function(mapSize){
    var key = this.getKeys().prefix + mapSize;
    return this.getCompletedGames()[key] || 0;
}
StatisticsClass.prototype.addCompletedGames = function(mapSize){
    var key = this.getKeys().prefix + mapSize;
    var arr = this.getCompletedGames();
    arr[key] ? arr[key]++ : arr[key] = 1;
}
